package com.xh.test;
import com.xh.dao.UserDao;
import com.xh.entity.User;
import com.xh.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;

public class SpringFactory {

    public static void main(String[] args){
//        ApplicationContext context=new ClassPathXmlApplicationContext("/spring-context.xml");
////        获取对象
////        UserDao userDao= (UserDao) context.getBean("userDao");
////        userDao.deleteUser(1);
//
//        UserService userService= (UserService) context.getBean("userService");
//        userService.deleteUser(2);
//


//        ApplicationContext context=new ClassPathXmlApplicationContext("/spring-context.xml");
//        User user= (User) context.getBean("user");
//        System.out.println(user);


//        ApplicationContext context=new ClassPathXmlApplicationContext("/spring-context.xml");
//        Connection conn= (Connection) context.getBean("conn");
//        System.out.println(conn);


        //启动工厂
        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("/spring-context2.xml");
        context.getBean("addr");
        context.getBean("addr");
        //关闭工厂
        context.close();


    }


//    public void testSet(){
//        System.out.println("111");
//        ApplicationContext context=new ClassPathXmlApplicationContext("/spring-context.xml");
//        User user= (User) context.getBean("user");
//
//
//    }
}
